package cn.cmcc.online.smsapi.ui.model;

import android.graphics.Color;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ZhangYifan on 2017/6/16.
 */

public class CarrierOperatorData {
    private int color;
    private String endTime;
    private Map<String, String> textList;
    private List<SmsProgress> progressList;

    public CarrierOperatorData(JSONObject data) {
        color = Color.parseColor(data.optString("title_color"));
        // TODO: 2017/6/18
        data = data.optJSONObject("data");
        endTime = data.optString("end_time");

        textList = new LinkedHashMap<>();
        JSONArray textArray = data.optJSONArray("text_list");
        if (textArray != null) {
            for (int i = 0; i < textArray.length(); i++) {
                JSONObject key_value = textArray.optJSONObject(i);
                textList.put(key_value.optString("title"), key_value.optString("content"));
            }
        }

        progressList = new ArrayList<>();
        JSONArray progressArray = data.optJSONArray("progress_list");
        if (progressArray != null) {
            for (int i = 0; i < progressArray.length(); i++) {
                JSONObject key_value = progressArray.optJSONObject(i);
                float total = (float) key_value.optDouble("total");
                float used = (float) key_value.optDouble("used");
                float left = (float) key_value.optDouble("left");
                String unit = key_value.optString("unit");
                String title = key_value.optString("title");
                progressList.add(new SmsProgress(title, total, used, left, unit));
            }
        }
    }

    public String getEndTime() {
        return endTime;
    }

    public Map<String, String> getTextList() {
        return textList;
    }

    public List<SmsProgress> getProgressList() {
        return progressList;
    }

    public int getColor() {
        return color;
    }
}
